import { MockMethod } from 'vite-plugin-mock'

interface RequestParams {
    query: {
        current?: string;
        pageSize?: string;
        productName?: string;
        platform?: string;
        version?: string;
        forceUpdate?: string;
        operator?: string;
        startTime?: string;
        endTime?: string;
    }
}

interface ListItem {
  id: number;
  productName: string;
  platform: string;
  version: string;
  forceUpdate: string;
  updateDescription: string;
  downloadUrl: string;
  operator: string;
  operationTime: string;
}

export default [
    {
        url: '/api/v1/app/version/list',
        method: 'get',
        response: ({ query }: RequestParams) => {
            const { 
                current = 1, 
                pageSize = 10,
                productName,
                platform,
                operator,
              forceUpdate,
                version
            } = query
            
            let list = Array(Number(pageSize)).fill(null).map((_, index) => ({
                id: (Number(current) - 1) * Number(pageSize) + index + 1,
                productName: productName || 'OP7',
                platform: platform || 'Android/IOS',
                version: 'v1.0.0',
                forceUpdate: index % 2 === 0 ? '是' : '否',
                updateDescription: '描述112312323232...',
                downloadUrl: String(index % 5),
                operator: operator || 'admin',
                operationTime: '2025-01-01'
            }))

            // 模拟搜索过滤
            if (productName) {
                list = list.filter((item: ListItem) => item.productName.includes(productName))
            }
            if (platform) {
                list = list.filter((item: ListItem) => item.platform === platform)
            }
            if (operator) {
                list = list.filter((item: ListItem) => item.operator.includes(operator))
            }
            if (forceUpdate) {
                list = list.filter((item: ListItem) => item.forceUpdate === (forceUpdate === '1' ? '是' : '否'))
            }
            if (version) {
                list = list.filter((item: ListItem) => item.version.includes(version))
            }

            return {
                code: 200,
                message: '操作成功',
                data: {
                    list,
                    total: 100
                }
            }
        }
    }
]

